package test.redis.tool;

import java.io.File;
import java.net.URISyntaxException;

import org.apache.log4j.Logger;

public class Utils {
    private static final Logger logger = Logger.getLogger(Utils.class);
    private static final String AGENT_CONFIG_FILE = "napm-common.properties";
    
    public static String getConfPath() {
        File agent = getAgentJar();
        File confFile = new File(agent.getParentFile().getParent(), "conf/" + AGENT_CONFIG_FILE);
        String confPath = confFile.getAbsolutePath();
        return confPath;
    }
    
    private static File getAgentJar() {
        File agent = null;
        try {
            String agentPath = Utils.class.getProtectionDomain().getCodeSource().getLocation().toURI().getPath();
            agent = new File(agentPath);
        } catch (URISyntaxException e) {
            logger.error("cannot get agent jar", e);
        }
        return agent;
    }

}
